package com.myjar.excel;

import com.myjar.excel.util.UnsupportedSerializeType;
import com.myjar.excel.v2.*;

import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.List;

// 客户端类
public class Excel {

    public static <T> Logger<T> write(List<T> list, Class<T> tClass) throws Exception {
        checkNotNullOrEmpty(list);
        WorkSpace<T> workSpace = new POiWorkSpace<>(tClass);
        return workSpace.write(list);
    }


    public static <T> Logger<T> read(InputStream inputStream, Class<T> tClass) throws Exception {
        WorkSpace<T> workSpace = new POiWorkSpace<>(tClass);
        return workSpace.read(inputStream);
    }

    private static void checkField(Field[] fields) throws ExcelException {
        if (fields == null ||
                fields.length == 0) {
            throw new ExcelException("没有需要序列化的字段");
        }
    }

    private static <T> void checkNotNullOrEmpty(List<T> list) throws ExcelException {
        if (list == null ||
                list.size() == 0) {
            throw new ExcelException("不支持空列表的初始化，请进行检查");
        }
    }
}
